layui.use(['layer', 'form', 'table', 'element','laydate'], function () {
    var layer = layui.layer;
    var $ = layui.jquery;
    var form = layui.form;
    var table = layui.table;
    var element = layui.element;
    var layDate = layui.laydate;

    //当前的查询条件的卡号类型和卡号
    var nowCardType = "";
    var nowCardNum = "";

    /**
     * 物联卡综合信息-基本信息
     */
    var BasicInfo = {
        tableId: "basicInfoTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""
        }
    };

    /**
     * gprs的APN信息查询条件
     */
    var SimGprsApnTable = {
        tableId: "simGprsApnTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""

        }
    };

    /**
     * gprs套餐内用量查询条件
     */
    var SimGprsComboTable = {
        tableId: "simGprsComboTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""
        }
    };

    /**
     * gprs流量池内用量查询条件
     */
    var SimGprsPoolTable = {
        tableId: "simGprsPoolTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""
        }
    };

    /**
     * 短信套餐内用量查询条件
     */
    var SimSmsTable = {
        tableId: "simSmsTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""
        }
    };

    /**
     * 语音套餐内用量查询条件
     */
    var SimVoiceComboTable = {
        tableId: "simVoiceComboTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""
        }
    };

    /**
     * 语音个人智能网语音信息查询条件
     */
    var SimVoiceUserTable = {
        tableId: "simVoiceUserTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""
        }
    };

    /**
     * 语音群组成员语音白名单查询条件
     */
    var SimVoiceGroupTable = {
        tableId: "simVoiceGroupTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: "",
            groupId:""
        }
    };

    /**
     * 充值结果查询
     */
    var SimRechargeResultTable = {
        tableId: "simRechargeResultTable",    //表格id
        condition: {
            queryWay: "",
            accountId:"",
            orderNo: "",
            startTime: "",
            endTime:""
        }
    };

    /**
     * 通信功能开通状态查询
     */
    var SimCommunicateTable = {
        tableId: "simCommunicateTable",    //表格id
        condition: {
            msisdn: "",
            iccid: "",
            imsi: ""
        }
    };

    /**
     * 物联卡机卡分离状态
     */
    var SimSecurityTable = {
        tableId: "simSecurityTable",    //表格id
        condition: {
            msisdn: "",
            testType: ""
        }
    };

    /**
     * 初始化基本信息表格的列
     */
    BasicInfo.initColumn = function () {
        return [[
            {field: 'accountId', hide: true, title: '账号id'},
            {field: 'msisdn', align: "center", title: 'MSISDN',minWidth: 200},
            {field: 'iccid', align: "center", title: 'ICCID',minWidth: 200},
            {field: 'imsi', align: "center", title: 'IMSI',minWidth: 200},
            {field: 'activeDate', align: "center", title: '激活时间',minWidth: 170},
            {field: 'openDate', align: "center", title: '开卡时间',minWidth: 170},
            {field: 'cardStatus', align: "center", title: '卡状态',minWidth: 100},
            {field: 'status', align: "center", title: '开关机状态',minWidth: 100},
            {field: 'imei', align: "center", title: '绑定IMEI',minWidth: 150},
            {field: 'platformType', align: "center", title: '归属平台',minWidth: 120},
            {field: 'dataAmount', align: "center", title: '本月流量累计用量（KB）',minWidth: 200},
            {field: 'smsAmount', align: "center", title: '本月短信累计用量（条）',minWidth: 200},
            {field: 'voiceAmount', align: "center", title: '本月语音累计用量（分钟）',minWidth: 220},
            {align: 'center', toolbar: '#menuGroup', title: '归属群组信息',minWidth: 130},
            {field: 'amount', align: "center",toolbar: '#menuBalance',title: '余额（元）',minWidth: 150},
            {field: 'errorCode', hide: true,align: "center", title: '余额错误标识',minWidth: 150},
            {align: 'center', toolbar: '#menuCharges', title: '已订购资费',minWidth: 100},
            {align: 'center', toolbar: '#menuStatus', title: '卡状态变更',minWidth: 100},
            {align: 'center', toolbar: '#menuHistoryStatus', title: '卡状态变更历史',minWidth: 140},
            {align: 'center', toolbar: '#menuNodeParam', title: '节电参数变更',minWidth: 130}
        ]];
    };

    /**
     * 初始化GPRS的APN信息表格的列
     */
    SimGprsApnTable.initColumn = function () {
        return [[
            {field: 'apnName', align: "center",  title: 'APN'},
            {field: 'serviceStatus', align: "center",  title: '服务状态'},
            {field: 'onlineStatus', align: "center",  title: '在线状态'},
            {field: 'ip', align: "center",  title: 'IP'},
            {field: 'createDate', align: "center",  title: '最近会话时间'},
            {field: 'rat', align: "center",  title: '接入方式'}
        ]];
    };

    /**
     * 初始化GPRS套餐内用量表格的列
     */
    SimGprsComboTable.initColumn = function () {
        return [[
            {field: 'offeringId', align: "center",  title: '资费ID'},
            {field: 'offeringName', align: "center",  title: '资费名称'},
            {field: 'apnName', align: "center",  title: 'APN名称'},
            {field: 'totalAmount', align: "center",  title: '本月套餐内总量(KB)'},
            {field: 'useAmount', align: "center",  title: '本月套餐内使用量(KB)'},
            {field: 'remainAmount', align: "center",  title: '本月套餐内剩余量(KB)'},
            {field: 'pccCode', align: "center",  title: 'pccServiceCode编码'}
        ]];
    };

    /**
     * 初始化GPRS流量池内用量表格的列
     */
    SimGprsPoolTable.initColumn = function () {
        return [[
            {field: 'apnName', align: "center",  title: 'APN'},
            {field: 'apnUseAmount', align: "center",  title: '流量池内用量（byte）'}
        ]];
    };

    /**
     * 初始化短信表格的列
     */
    SimSmsTable.initColumn = function () {
        return [[
            {field: 'offeringId', align: "center",  title: '资费ID'},
            {field: 'offeringName', align: "center",  title: '资费名称'},
            {field: 'totalAmount', align: "center",  title: '本月套餐内总量（条）'},
            {field: 'useAmount', align: "center",  title: '本月套餐内使用量(条）'},
            {field: 'remainAmount', align: "center",  title: '本月套餐内剩余量(条）'}
        ]];
    };

    /**
     * 初始化语音套餐内用量表格的列
     */
    SimVoiceComboTable.initColumn = function () {
        return [[
            {field: 'offeringId', align: "center",  title: '资费ID'},
            {field: 'offeringName', align: "center",  title: '资费名称'},
            {field: 'totalAmount', align: "center",  title: '本月套餐内总量（条）'},
            {field: 'useAmount', align: "center",  title: '本月套餐内使用量(条）'},
            {field: 'remainAmount', align: "center",  title: '本月套餐内剩余量(条）'}
        ]];
    };

    /**
     * 初始化个人智能网语音信息表格的列
     */
    SimVoiceUserTable.initColumn = function () {
        return [[
            {field: 'changeDate', align: "center",  title: '变更时间'},
            {field: 'perThresLevel', align: "center",  title: '通话阈值级别'},
            {field: 'calledLock', align: "center",  title: '被叫闭锁'},
            {field: 'whiteStatus', align: "center",  title: '白名单状态'},
            {field: 'limitSign', align: "center",  title: '限制标识'}
        ]];
    };

    /**
     * 初始化群组成员语音白名单表格的列
     */
    SimVoiceGroupTable.initColumn = function () {
        return [[
            {field: 'whiteNumber', align: "center",  title: '白名单号码(MSISDN)'},
            {field: 'status', align: "center",  title: '白名单状态'}
        ]];
    };

    SimSecurityTable.initColumn = function () {
        return [[
            {field: "result", align: "center", title: "分离状态", width: 100},
            {field: "sepTime", align: "center", title: "分离时间<br/>（仅“话单侧检测”时返回）", width: 200},
            {field: "errorCode", align: "center", title: "错误码<br/>（当查询失败时返回）", width: 200},
            {field: "errorDes", align: "center", title: "错误描述<br/>（当查询失败时返回）", width: 500}
        ]];
    };

    /**
     * 初始化充值结果查询表格的列
     */
    SimRechargeResultTable.initColumn = function () {
        return [[
            {field: 'orderTime', align: "center", title: '订单生成时间'},
            {field: 'orderNo', align: "center", title: '订单号'},
            {field: 'accountId', align: "center", title: '账户ID'},
            {field: 'accountName', align: "center", title: '账户名称'},
            {field: 'chargeMoney', align: "center", title: '充值金额（元）'},
            {field: 'resultCode', align: "center", title: '订单处理结果'},
            {field: 'resultDesc', align: "center", title: '订单处理描述'}
        ]];
    };

    /**
     * 初始化通信同能开通状态查询表格的列
     */
    SimCommunicateTable.initColumn = function () {
        return [[
            {field: 'serviceType', align: "center", title: '通信功能服务'},
            {field: 'serviceStatus', align: "center", title: '通信功能服务状态'},
            {field: 'apnName', align: "center", title: 'APN名称'}
        ]];
    };

    /**
     * 选项卡点击事件
     *
     * 切换选项卡，加载对应的数据表
     */
    $("#gprs").show();
    $("#sms").hide();
    $("#voice").hide();
    $("#security").hide();
    $("#recharge").hide();
    $("#communicate").hide();
    element.on('tab(demo)', function (data) {
        index = data.index;
        if (data.index == "0") {
            simGprsApnRender();
            simGprsComboRender();
            simGprsPoolRender();
            $("#gprs").show();
            $("#sms").hide();
            $("#voice").hide();
            $("#recharge").hide();
            $("#security").hide();
            $("#communicate").hide();
        } else if (data.index == "1") {
            simSmsRender();
            $("#gprs").hide();
            $("#sms").show();
            $("#voice").hide();
            $("#recharge").hide();
            $("#security").hide();
            $("#communicate").hide();
        } else if (data.index == "2") {
            simVoiceComboRender();
            simVoiceUserRender();
            simVoiceGroupRender();
            $("#gprs").hide();
            $("#sms").hide();
            $("#voice").show();
            $("#recharge").hide();
            $("#security").hide();
            $("#communicate").hide();
        } else if (data.index == "3") {
            simRechargeResultRender();
            $("#gprs").hide();
            $("#sms").hide();
            $("#voice").hide();
            $("#recharge").show();
            $("#security").hide();
            $("#communicate").hide();
        } else if (data.index == "4") {
            machineCardStatus();
            $("#gprs").hide();
            $("#sms").hide();
            $("#voice").hide();
            $("#recharge").hide();
            $("#security").show();
            $("#communicate").hide();
        } else if (data.index == "5") {
            simCommunicateRender();
            $("#gprs").hide();
            $("#sms").hide();
            $("#voice").hide();
            $("#recharge").hide();
            $("#security").hide();
            $("#communicate").show();
        }
    });

    // 渲染基本信息表格
    basicInfoRender();
    simGprsApnRender();
    simGprsComboRender();
    simGprsPoolRender();
    function basicInfoRender() {
        table.render({
            elem: '#' + BasicInfo.tableId,
            url: Feng.ctxPath + '/general/list',
            page: false,
            height: 100,
            cellMinWidth: 100,
            cols: BasicInfo.initColumn()
        });
    }

    /**
     * 物联卡基本信息点击查询按钮
     */
    BasicInfo.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#msisdn").val();
        queryData['iccid'] = $("#iccid").val();
        queryData['imsi'] = $("#imsi").val();
        table.reload(BasicInfo.tableId, {
            where: queryData
        });
    };

    $("#btnSearch").click(function () {
        var msisdnVal = $("#msisdn").val();
        var iccidVal = $("#iccid").val();
        var imsiVal = $("#imsi").val();
        var count = 0;
        if ('' != msisdnVal) {
            nowCardType = "msisdn";
            nowCardNum = msisdnVal;
            count++;
        }
        if ('' != iccidVal) {
            nowCardType = "iccid";
            nowCardNum = iccidVal;
            count++;
        }
        if ('' != imsiVal) {
            nowCardType = "imsi";
            nowCardNum = imsiVal;
            count++;
        }
        if (count == 0 || count > 1) {
            Feng.error("MSISDN、ICCID、IMSI必须有且只有一项！");
            return;
        }
        BasicInfo.search();
    });

    /**
     * 物联卡GPRS上网功能重置按钮
     */
    $("#gprsReset").click(function () {
        layer.open({
            type: 2,
            title: '物联卡GPRS上网功能重置',
            area: ['850px', '350px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/simInfoForGprs/toResetGprsNetFunction'
        });
    });

    /**
     * 物联卡 GPRS（自主）限速按钮
     */
    $("#gprsLimit").click(function () {
        layer.open({
            type: 2,
            title: '物联卡 GPRS（自主）限速',
            area: ['850px', '450px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/simInfoForGprs/toGprsLimitSpeed'
        });
    });

    /**
     * 物联卡GPRS（PCC策略）限速按钮
     */
    $("#gprsPCC").click(function () {
        layer.open({
            type: 2,
            title: '物联卡GPRS（PCC策略）限速',
            area: ['850px', '520px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/simInfoForGprs/toGprsPccLimitSpeed'
        });
    });

    /**
     * 物联卡流量叠加包订购按钮
     */
    $("#gprsOrder").click(function () {
        layer.open({
            type: 2,
            title: '物联卡流量叠加包订购',
            area: ['880px', '480px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/simInfoForGprs/toGprsPackageOrder'
        });
    });

    /**
     * 物联卡短信状态重置
     */
    $("#smsStatusReset").click(function () {
        layer.open({
            type: 2,
            title: '物联卡短信状态重置',
            area: ['850px', '350px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/generalSms/toResetSimSmsStatus',
        });
    });

    /**
     * 群组成员语音白名单管理
     */
    $("#voiceWhiteList").click(function () {
        layer.open({
            type: 2,
            title: '群组成员语音白名单管理',
            area: ['850px', '570px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/simInfoForVoice/toManagerGroupVoiceWhite'
        });
    });

    /**
     * 充值-物联卡账户充值交费
     */
    $("#rechargePay").click(function () {
        layer.open({
            type: 2,
            title: '物联卡账户充值交费',
            area: ['850px', '650px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/generalRecharge/toRechargeSimAccount'
        });
    });

    /**
     * 通信-基础通信功能开停
     */
    $("#comBasicOnOff").click(function () {
        layer.open({
            type: 2,
            title: '物联卡基础通信功能开停',
            area: ['850px', '530px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/generalCommunicate/toSimCommunicationFunctionBatch'
        });
    });

    /**
     * 通信-APN功能开停
     */
    $("#comApnOnOff").click(function () {
        layer.open({
            type: 2,
            title: '物联卡APN功能开停',
            area: ['850px', '530px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/generalCommunicate/toOperateApnFunction'
        });
    });

    /**
     * 通信-短信功能开停
     */
    $("#comSmsOnOff").click(function () {
        layer.open({
            type: 2,
            title: '物联卡短信功能开停',
            area: ['850px', '500px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/generalCommunicate/toSimSmsFunction'
        });
    });

    /**
     * 通信-语音功能开停
     */
    $("#comVoiceOnOff").click(function () {
        layer.open({
            type: 2,
            title: '物联卡语音功能开停',
            area: ['850px', '500px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/generalCommunicate/toSimCallFunction'
        });
    });

    /**
     * 通信-数据通信服务（PCC策略）开停
     */
    $("#comPccOnOff").click(function () {
        layer.open({
            type: 2,
            title: '数据通信服务（PCC策略）开停',
            area: ['850px', '530px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/generalCommunicate/toSimGprsPccFunctionBatch'
        });
    });

    /**
     * 查询物联卡GPRS的APN信息
     */
    SimGprsApnTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#gprsMsisdn").val();
        queryData['iccid'] = $("#gprsIccid").val();
        queryData['imsi'] = $("#gprsImsi").val();
        table.reload(SimGprsApnTable.tableId, {
            where: queryData
        });
    };

    /**
     * 查询物联卡GPRS的套餐内用量信息
     */
    SimGprsComboTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#gprsMsisdn").val();
        queryData['iccid'] = $("#gprsIccid").val();
        queryData['imsi'] = $("#gprsImsi").val();
        table.reload(SimGprsComboTable.tableId, {
            where: queryData
        });
    };

    /**
     * 查询物联卡GPRS的流量池用量信息
     */
    SimGprsPoolTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#gprsMsisdn").val();
        queryData['iccid'] = $("#gprsIccid").val();
        queryData['imsi'] = $("#gprsImsi").val();
        table.reload(SimGprsPoolTable.tableId, {
            where: queryData
        });
    };

    /**
     * 物联卡GPRS点击查询按钮
     */
    $("#btnSearchGprs").click(function () {
        var msisdnVal = $("#gprsMsisdn").val();
        var iccidVal = $("#gprsIccid").val();
        var imsiVal = $("#gprsImsi").val();
        var count = 0;
        if ('' != msisdnVal) {
            count++;
        }
        if ('' != iccidVal) {
            count++;
        }
        if ('' != imsiVal) {
            count++;
        }
        if (count == 0 || count > 1) {
            Feng.error("MSISDN、ICCID、IMSI必须有且只有一项！");
            return;
        }
        SimGprsApnTable.search();
        SimGprsComboTable.search();
        SimGprsPoolTable.search();
    });

    /**
     * 查询物联卡短信套餐内用量信息
     */
    SimSmsTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#smsMsisdn").val();
        queryData['iccid'] = $("#smsIccid").val();
        queryData['imsi'] = $("#smsImsi").val();
        table.reload(SimSmsTable.tableId, {
            where: queryData
        });
    };

    /**
     * 物联卡短信点击查询按钮
     */
    $("#btnSearchSms").click(function () {
        var msisdnVal = $("#smsMsisdn").val();
        var iccidVal = $("#smsIccid").val();
        var imsiVal = $("#smsImsi").val();
        var count = 0;
        if ('' != msisdnVal) {
            count++;
        }
        if ('' != iccidVal) {
            count++;
        }
        if ('' != imsiVal) {
            count++;
        }
        if (count == 0 || count > 1) {
            Feng.error("MSISDN、ICCID、IMSI必须有且只有一项！");
            return;
        }
        SimSmsTable.search();
    });

    /**
     * 查询物联卡语音套餐内用量信息
     */
    SimVoiceComboTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#voiceComboMsisdn").val();
        queryData['iccid'] = $("#voiceComboIccid").val();
        queryData['imsi'] = $("#voiceComboImsi").val();
        table.reload(SimVoiceComboTable.tableId, {
            where: queryData
        });
    };

    /**
     * 查询物联卡语音-个人智能网语音信息
     */
    SimVoiceUserTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#voiceComboMsisdn").val();
        queryData['iccid'] = $("#voiceComboIccid").val();
        queryData['imsi'] = $("#voiceComboImsi").val();
        table.reload(SimVoiceUserTable.tableId, {
            where: queryData
        });
    };

    /**
     * 物联卡语音顶部查询按钮
     */
    $("#btnSearchVoiceCombo").click(function () {
        var msisdnVal = $("#voiceComboMsisdn").val();
        var iccidVal = $("#voiceComboIccid").val();
        var imsiVal = $("#voiceComboImsi").val();
        var count = 0;
        if ('' != msisdnVal) {
            count++;
        }
        if ('' != iccidVal) {
            count++;
        }
        if ('' != imsiVal) {
            count++;
        }
        if (count == 0 || count > 1) {
            Feng.error("MSISDN、ICCID、IMSI必须有且只有一项！");
            return;
        }
        SimVoiceComboTable.search();
        SimVoiceUserTable.search();
    });

    /**
     * 查询物联卡语音-群组成员语音白名单信息
     */
    SimVoiceGroupTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#voiceGroupMsisdn").val();
        queryData['iccid'] = $("#voiceGroupIccid").val();
        queryData['imsi'] = $("#voiceGroupImsi").val();
        queryData['groupId'] = $("#voiceGroupId").val();
        table.reload(SimVoiceGroupTable.tableId, {
            where: queryData
        });
    };

    /**
     * 物联卡语音底部查询按钮
     */
    $("#btnSearchVoiceGroup").click(function () {
        var msisdnVal = $("#voiceGroupMsisdn").val();
        var iccidVal = $("#voiceGroupIccid").val();
        var imsiVal = $("#voiceGroupImsi").val();
        var groupIdVal = $("#voiceGroupId").val();
        if ('' == groupIdVal) {
            Feng.error("归属群组ID不能为空值！");
            return;
        }
        var count = 0;
        if ('' != msisdnVal) {
            count++;
        }
        if ('' != iccidVal) {
            count++;
        }
        if ('' != imsiVal) {
            count++;
        }
        if (count == 0 || count > 1) {
            Feng.error("MSISDN、ICCID、IMSI必须有且只有一项！");
            return;
        }
        SimVoiceGroupTable.search();
    });

    /**
     * 查询物联卡充值-充值结果查询
     */
    SimRechargeResultTable.search = function () {
        var queryData = {};
        var starttime = $("#startTime").val();
        var endtime = $("#endTime").val();
        var startTime= new Date(Date.parse(starttime));
        var endTime=new Date(Date.parse(endtime));
        if (startTime >= endTime) {
            Feng.error("结束时间必须晚于开始时间！");
            return;
        }
        if($("#queryWay").val() === "0"){
            if($("#orderNo").val() === "") {
                Feng.error("通过充值订单号查询时订单号不能为空！");
                return;
            }
        }
        if($("#queryWay").val() === "1"){
            if($("#startTime").val() === "") {
                Feng.error("通过时间查询时开始时间不能为空！");
                return;
            }
        }
        if($("#queryWay").val() === "1"){
            if($("#endTime").val() === "") {
                Feng.error("通过时间查询时结束时间不能为空！");
                return;
            }
        }
        queryData['queryWay'] = $("#queryWay").val();
        queryData['accountId'] = $("#accountId").val();
        queryData['orderNo'] = $("#orderNo").val();
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        table.reload(SimRechargeResultTable.tableId, {
            where: queryData
        });
    };

    /**
     * 查询物联卡充值-充值结果查询
     */
    $("#btnSearchRecharge").click(function () {
        SimRechargeResultTable.search();
    });

    /**
     * 查询物联卡通信-通信功能开通状态
     */
    SimCommunicateTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#comMsisdn").val();
        queryData['iccid'] = $("#comIccid").val();
        queryData['imsi'] = $("#comImsi").val();
        table.reload(SimCommunicateTable.tableId, {
            where: queryData
        });
    };

    /**
     * 查询物联卡通信-通信功能开通状态查询按钮
     */
    $("#btnSearchCom").click(function () {
        var msisdnVal = $("#comMsisdn").val();
        var iccidVal = $("#comIccid").val();
        var imsiVal = $("#comImsi").val();
        var count = 0;
        if ('' != msisdnVal) {
            count++;
        }
        if ('' != iccidVal) {
            count++;
        }
        if ('' != imsiVal) {
            count++;
        }
        if (count == 0 || count > 1) {
            Feng.error("MSISDN、ICCID、IMSI必须有且只有一项！");
            return;
        }

        SimCommunicateTable.search();
    });

    //工具条点击事件
    table.on('tool(' + BasicInfo.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'menuGroup') {
            BasicInfo.searchMenuGroup(data);
        }else if (layEvent === 'menuBalance') {
            BasicInfo.searchMenuBalance(data);
        }else if (layEvent === 'menuCharges') {
            BasicInfo.searchMenuCharges(data);
        }else if (layEvent === 'menuStatus') {
            BasicInfo.searchMenuStatus(data);
        }else if (layEvent === 'menuHistoryStatus') {
            BasicInfo.searchMenuHistoryStatus(data);
        }else if (layEvent === 'menuNodeParam') {
            BasicInfo.searchMenuNodeParam(data);
        }
    });

    /**
     * 查看物联卡归属群组信息
     *
     * @param data 点击按钮时候的行数据
     */
    BasicInfo.searchMenuGroup = function (data) {
        layer.open({
            type: 2,
            title: '物联卡归属群组信息',
            area: ['850px', '550px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/general/general_group/' + data.accountId + '/' + nowCardType + '/' + nowCardNum,
            btn: ['关闭']
        });
    };

    /**
     * 查看余额信息
     *
     * @param data 点击按钮时候的行数据
     */
    BasicInfo.searchMenuBalance = function (data) {
        if(data.errorCode === 0){
            layer.open({
                type: 2,
                title: '余额信息',
                area: ['500px', '400px'],
                skin: 'layui-layer-molv',
                content: Feng.ctxPath + '/general/general_balance/' + data.accountId + '/' + nowCardType + '/' + nowCardNum,
                btn: ['关闭']
            });
        }
    };


    /**
     * 查看物联卡已订购资费
     *
     * @param data 点击按钮时候的行数据
     */
    BasicInfo.searchMenuCharges = function (data) {
        layer.open({
            type: 2,
            title: '物联卡已订购资费',
            area: ['1050px', '650px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/general/ordered_charges/' + data.accountId + '/' + nowCardType + '/' + nowCardNum,
            btn: ['关闭']
        });
    };

    /**
     * 查看物联卡状态变更
     *
     * @param data 点击按钮时候的行数据
     */
    BasicInfo.searchMenuStatus = function (data) {
        layer.open({
            type: 2,
            title: '物联卡状态变更',
            area: ['850px', '450px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/general/changeable_status/' + data.accountId
        });
    };

    /**
     * 查看物联卡状态变更历史
     *
     * @param data 点击按钮时候的行数据
     */
    BasicInfo.searchMenuHistoryStatus = function (data) {
        layer.open({
            type: 2,
            title: '物联卡状态变更历史',
            area: ['850px', '550px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/general/history_status/' + data.accountId + '/' + nowCardType + '/' + nowCardNum,
            btn: ['关闭']
        });
    };

    /**
     * 物联卡节电参数变更
     *
     * @param data 点击按钮时候的行数据
     */
    BasicInfo.searchMenuNodeParam = function (data) {
        layer.open({
            type: 2,
            title: '物联卡节电参数变更',
            area: ['850px', '670px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/general/change_paramNode/' + data.accountId
        });
    };

    // 渲染GPRS表格
    function simGprsApnRender() {
        table.render({
            elem: '#' + SimGprsApnTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/simInfoForGprs/singleCardApnInfo',
            page: true,
            limit: 5,
            limits: [5],
            height: 350,
            cellMinWidth: 100,
            cols: SimGprsApnTable.initColumn()
        });
    }

    function simGprsComboRender() {
        table.render({
            elem: '#' + SimGprsComboTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/simInfoForGprs/packageGprsUsed',
            page: true,
            limit: 5,
            limits: [5],
            height: 350,
            cellMinWidth: 100,
            cols: SimGprsComboTable.initColumn()
        });
    }

    function simGprsPoolRender() {
        table.render({
            elem: '#' + SimGprsPoolTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/simInfoForGprs/singleCardPoolUsed',
            page: true,
            limit: 5,
            limits: [5],
            height: 350,
            cellMinWidth: 100,
            cols: SimGprsPoolTable.initColumn()
        });
    }

    // 渲染短信表格
    function simSmsRender() {
        table.render({
            elem: '#' + SimSmsTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/generalSms/querySimSmsMargin',
            page: true,
            limit: 5,
            limits: [5],
            height: 350,
            cellMinWidth: 100,
            cols: SimSmsTable.initColumn()
        });
    }

    // 渲染语音表格
    function simVoiceComboRender() {
        table.render({
            elem: '#' + SimVoiceComboTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/simInfoForVoice/packageVoiceUsed',
            page: true,
            limit: 5,
            limits: [5],
            height: 350,
            cellMinWidth: 100,
            cols: SimVoiceComboTable.initColumn()
        });
    }

    function simVoiceUserRender() {
        table.render({
            elem: '#' + SimVoiceUserTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/simInfoForVoice/smartVoiceInfo',
            page: true,
            limit: 5,
            limits: [5],
            height: 350,
            cellMinWidth: 100,
            cols: SimVoiceUserTable.initColumn()
        });
    }

    function simVoiceGroupRender() {
        table.render({
            elem: '#' + SimVoiceGroupTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/simInfoForVoice/groupVoiceWhite',
            page: true,
            limit: 5,
            limits: [5],
            height: 350,
            cellMinWidth: 100,
            cols: SimVoiceGroupTable.initColumn()
        });
    }

    /**
     * 物联卡机卡分离状态
     */
    function machineCardStatus() {
        table.render({
            elem: '#' + SimSecurityTable.tableId,
            loading: false,
            height: 350,
            cellMinWidth: 100,
            cols: SimSecurityTable.initColumn()
        });
    }

    /**
     * 物联卡机卡分离状态，点击查询
     */
    $("#btnSearchSecurity").click(function () {
        var msisdnVal = $("#securityMsisdn").val();
        if ("" == msisdnVal) {
            Feng.error("请输入要查询的物联卡MSISDN号！");
            return;
        }
        SimSecurityTable.search();
    });

    /**
     * 物联卡机卡分离状态，查询方法
     */
    SimSecurityTable.search = function() {
        var queryData = {};
        queryData['msisdn'] = $("#securityMsisdn").val();
        queryData['testType'] = $("#securityTestType").val();
        table.reload(SimSecurityTable.tableId, {
            url: Feng.ctxPath + '/security/machineCardSeparateStatus',
            where: queryData
        });
    }
    /**
     * 打开机卡绑定操作页面
     */
    $("#machineCard").click(function () {
        layer.open({
            type: 2,
            title: '机卡绑定/变更/解绑',
            area: ['850px', '650px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/security/toMachineCardBind'
        });
    });
    /**
     * 打开物联卡实名登记页面
     */
    $("#cardRegister").click(function () {
        layer.open({
            type: 2,
            title: "物联卡实名登记",
            area: ['950px', '550px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/security/toSimRegister'
        });
    });

    $("#apnGprsAlarm").click(function () {
        layer.open({
            type: 2,
            title: "物联卡APN流量告警规则设置",
            area: ['850px', '550px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/security/toApnGprsAlarm'
        });
    });

    //渲染充值结果查询表格
    function simRechargeResultRender() {
        table.render({
            elem: '#' + SimRechargeResultTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/generalRecharge/queryRechargeResult',
            page: true,
            limit: 10,
            limits: [10,20,30,40,50],
            height: "full-98",
            cellMinWidth: 100,
            cols: SimRechargeResultTable.initColumn()
        });
    }

    //渲染通信功能开通状态表格
    function simCommunicateRender() {
        table.render({
            elem: '#' + SimCommunicateTable.tableId,
            defaultToolbar: [],
            url: Feng.ctxPath + '/generalCommunicate/queryCommunicateFunctionStatus',
            page: true,
            limit: 10,
            limits: [10],
            height: "full-98",
            cellMinWidth: 100,
            cols: SimCommunicateTable.initColumn()
        });
    }

    //渲染时间
    layDate.render({
        elem: '#startTime',
        format:'yyyyMMddHHmmss',
        type: 'datetime'
    });

    layDate.render({
        elem: '#endTime',
        format:'yyyyMMddHHmmss',
        type: 'datetime'
    });

    /**
     * 查询所有的账号信息，填充select标签
     */
    function searchAccount(accountId) {
        $('#accountId').html('');
        $("#accountId").append('<option value="" >请选择</option>');
        $.ajax({
            type: 'get',
            url: Feng.ctxPath + "/account/allSelectAccounts",
            async: false,
            success: function (data) {
                for (var i = 0; i < data.data.length; i++) {
                    var name = data.data[i].accountName;
                    var code = data.data[i].accountId;
                    if (accountId == code) {
                        $("#accountId").append('<option value="' + code + '" selected>' + name + '</option>');
                    } else {
                        $("#accountId").append('<option value="' + code + '">' + name + '</option>');
                    }
                }
                form.render('select');
            }
        });
    }
    searchAccount();

});